using System;
using System.Diagnostics;
using System.Globalization;

namespace Atomic.Libraries.Physics.Units
{
	[Serializable]
	[DebuggerDisplay("{DebuggerDisplay}")]
	public class Temperature : IQuantity
	{
		private double value;

		private Temperature(double value)
		{
			this.value = value;
		}

		public static Temperature FromUnit(IUnitSystem system, double value)
		{
			if (system.TemperatureScaling == 1.0)
			{
				return new Temperature(value);
			}
			else
			{
				return new Temperature(value / system.TemperatureScaling);
			}
		}

		public static Temperature FromKelvin(double value)
		{
			return FromUnit(UnitSystem.InternationalSystem, value);
		}

		public double ToUnit(IUnitSystem system)
		{
			if (system.TemperatureScaling == 1.0)
			{
				return value;
			}
			else
			{
				return value * system.TemperatureScaling;
			}
		}

		public double ToKelvin()
		{
			return ToUnit(UnitSystem.InternationalSystem);
		}

		public static implicit operator double(Temperature value)
		{
			return value.ToUnit(UnitSystem.AtomicSystem);
		}

		public static implicit operator Temperature(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}

		/*public static bool operator ==(Temperature value1, Temperature value2)
		{
			return value1.value == value2.value;
		}

		public static bool operator !=(Temperature value1, Temperature value2)
		{
			return value1.value != value2.value;
		}

		public static bool operator <(Temperature value1, Temperature value2)
		{
			return value1.value < value2.value;
		}

		public static bool operator >(Temperature value1, Temperature value2)
		{
			return value1.value > value2.value;
		}

		public static bool operator <=(Temperature value1, Temperature value2)
		{
			return value1.value <= value2.value;
		}

		public static bool operator >=(Temperature value1, Temperature value2)
		{
			return value1.value >= value2.value;
		}*/

		private string DebuggerDisplay
		{
			get
			{
				return string.Format(CultureInfo.InvariantCulture, "{0} K", ToKelvin());
			}
		}
	}
}
